#!/bin/bash
#用来安装最普通的openresty服务器环境

#==========将所有文件拷贝到 /home/ 目录下  =======
#chmod 700 /home/install_std_server_env.sh
#=================================================
#如果脚本或者输出是乱码，使用LANG设置一下：LANG="en_US.UTF-8"


#用法：
#/home/install_std_server_env_or.sh  dir         ----安装基本目录
#/home/install_std_server_env_or.sh  software    ----安装必要的软件
#/home/install_std_server_env_or.sh  or          ----安装openresty
#/home/install_std_server_env_or.sh  ssdb        ----安装ssdb
#/home/install_std_server_env_or.sh  common_or   ----安装上述全部


if  [ -d "/data/rent_server/rentRsyncRoot" ]; then
	echo "THIS IS THE DEV ENV, IGNORED1..."
	echo "这里是测试环境，已经安装完毕，千万别在测试环境执行这个脚本，避免洗掉配置"
	exit
fi


if  [ -f "/home/install_std_server_func_lib.txt" ]; then
	. /home/install_std_server_func_lib.txt
	test_lib
else
	echo "未能找到成功加载库函数文件 /home/install_std_server_func_lib.txt"
	exit 1
fi


if  [ -d "/data/" ]; then
	echo "check /data/ ok"
else
	echo "error: no /data/ dir"
	exit
fi



#==============================================
#================= commands ===================
#==============================================


echo "================= try install $1"

echo "begin "$1

if  [ "$1" == "dir" ]; then
    func_install_dir

elif  [ "$1" == "software" ]; then
    func_install_software

elif  [ "$1" == "or" ]; then
    func_install_openresty

elif  [ "$1" == "ssdb" ]; then
    func_install_ssdb

elif  [ "$1" == "or_ln" ]; then
    func_or_ln

elif  [ "$1" == "rsync_or_code" ]; then
    rsyncd_132_lua_code_files $2

elif  [ "$1" == "common_or" ]; then
	func_install_dir
	func_install_software
	func_install_openresty
	#func_install_ssdb
	func_or_ln
	copy_lua_env0


elif  [ "$1" == "rsync_home" ]; then
	func_rsync_132_or_home

elif  [ "$1" == "crontab_reporter" ]; then
	func_install_crontab

elif  [ "$1" == "copy_lua_env0" ]; then
	copy_lua_env0

elif  [ "$1" == "start_reload_sh" ]; then
	install_start_reload_nginx_sh

elif  [ "$1" == "keeper_server_conf" ]; then
	func_install_keeper_server

elif  [ "$1" == "dc_server_conf" ]; then
	func_install_dc_server

elif  [ "$1" == "ma_gate_server_conf" ]; then
	func_install_ma_gate_server

elif  [ "$1" == "dc_gate_server_conf" ]; then
	func_install_dc_gate_server

else
    echo "================= error params ================"	
	echo "/home/install_std_server_env.sh  rsync_home           #同步home目录下的安装文件"
	echo "-----------------------------------------------------------------------"
	echo "/home/install_std_server_env.sh  dir                  #安装必须的目录结构"
    echo "/home/install_std_server_env.sh  software             #安装外部软件"
	echo "/home/install_std_server_env.sh  or                   #安装openresty"
	echo "/home/install_std_server_env.sh  or_ln                #安装openresty目录下的软连接"
	echo "-----------------------------------------------------------------------"
	echo "/home/install_std_server_env.sh  common_or            #安装以上全部(基础openresty环境)(推荐)"
	echo "/home/install_std_server_env.sh  ssdb                 #安装ssdb"
	echo "/home/install_std_server_env.sh  crontab_reporter     #安装系统监控"
	echo "-----------------------------------------------------------------------"
	echo "/home/install_std_server_env.sh  copy_lua_env0        #同步env.lua"
	echo "/home/install_std_server_env.sh  rsync_or_code        #同步openresty-lua代码"	
	echo "-----------------------------------------------------------------------"	
	echo "/home/install_std_server_env.sh  keeper_server_conf   #安装监控keeper"
	echo "/home/install_std_server_env.sh  dc_server_conf       #安装data_cache"
	echo "/home/install_std_server_env.sh  ma_gate_server_conf  #安装ma_gate_server"
	echo "/home/install_std_server_env.sh  dc_gate_server_conf  #安装dc_gate_server"
	echo "-----------------------------------------------------------------------"
    exit 0
fi


echo "================= install $1 ok"
pwd







